package com.ssm.juc.threadpool;

import java.util.concurrent.*;

/**
 * VM ARG: -Xms8m -Xmx8m
 */
public class ExecutorsTest2 {
    private static ThreadFactory namedThreadFactory = new ThreadFactory() {
        int index = 0;

        @Override
        public Thread newThread(Runnable r) {
            return new Thread(r, "demo-pool-%d" + (index++));
        }
    };

    private static ExecutorService pool = new ThreadPoolExecutor(5, 200, 0L,
            TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue(1024), namedThreadFactory,
            new ThreadPoolExecutor.AbortPolicy());

    public static void main(String[] args) {
        for (int i = 0; i < Integer.MAX_VALUE; i++) {
            pool.execute(new SubThread());
        }
    }
}

class SubThread implements Runnable {
    @Override
    public void run() {
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            //do nothing
        }
    }
}